package com.danieldura.highrise.data
{
	import com.adobe.utils.DateUtil;
	
	public class Company implements HighriseData
	{
		public var id:int;
		public var name:String;
		public var background:String;
		public var createdAt:Date;
		public var updatedAt:Date;
		public var visibleTo:String;
		public var ownerId:int;
		public var groupId:int;
		public var authorId:int;
		public var contactData:ContactData;
	
		public function parse( data:XML ):void
		{
			id = data.id;
			name = data.name;
			background = data.background;
			createdAt = DateUtil.parseW3CDTF( data["created-at"] );
			updatedAt = DateUtil.parseW3CDTF( data["updated-at"] );
			visibleTo = data["visible-to"];
			ownerId = data["owner-id"];
			groupId = data["group-id"];
			authorId = data["author-id"];
			
			contactData = new ContactData();
			contactData.parse( data["contact-data"][0] );
		}
		
		public function toXML():XML
		{
			var data:XML = new XML( <company /> );
			data.id = id;
			data.name = name;
			data.background = background;
			data.visibleTo = data["visible-to"];
			data.groupId = data["group-id"];
			data.appendChild( contactData.toXML() );
			return data;
		}
		
		public function toXMLString():String
		{
			return toXML().toXMLString();
		}
	}
}

/*
<company>
  <id type="integer">1</id>
  <name>Doe Inc.</name>
  <background>A popular company for random data</background>
  <created-at type="datetime">2007-02-27T03:11:52Z</created-at>
  <updated-at type="datetime">2007-03-10T15:11:52Z</updated-at>
  <visible-to>#{Everyone || Owner || NamedGroup}</visible-to>
  <owner-id type="integer">#{ user_id -- requires visble-to is "Owner"}</owner-id>
  <group-id type="integer">#{ group_id -- requires visble-to is "NamedGroup"}</group-id>
  <author-id type="integer">3</author-id>
  <contact-data>
    ...
  </contact-data>
</company>
*/